﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using Maticsoft.DBUtility;
using Utils;
using System.Collections.Specialized;
using Maticsoft.Model;


public partial class team_seconds : FBasePage
{
    // Fields
    private DateTime beginTime = DateTime.Now;

    public string strNav = "";

    // Methods
    private void initNav()
    {
        StringBuilder builder = new StringBuilder();
        string str = "";
        if ((base.Request["gid"] == null) || (base.Request["gid"].ToString() == ""))
        {
            str = "";
            builder.Append("<li class=\"current\"><a href=\"/team/seconds.aspx\">所有</a><span></span></li>");
        }
        else
        {
            str = base.Request["gid"].ToString();
            builder.Append("<li ><a href=\"/team/seconds.aspx\">所有</a><span></span></li>");
        }
        Maticsoft.BLL.Category category = new Maticsoft.BLL.Category();
        if ((base.ASSystem != null) && (base.ASSystem.Cateseconds == 1))
        {
            DataSet list = category.GetList(" Zone='group' and Display='Y' order by Sort_order desc");
            if ((list.Tables.Count > 0) && (list.Tables[0].Rows.Count > 0))
            {
                for (int i = 0; i < list.Tables[0].Rows.Count; i++)
                {
                    DataRow row = list.Tables[0].Rows[i];
                    builder.Append("<li ");
                    if (str == row["id"].ToString())
                    {
                        builder.Append("class=\"current\" ");
                    }
                    builder.Append(" ><a href=\"/team/seconds.aspx?gid=" + row["id"].ToString() + "\">" + row["Name"].ToString() + "</a><span></span></li>");
                }
            }
        }
        this.strNav = builder.ToString();
    }

    private void initPage()
    {
        int num;
        string str = "";
        if ((base.Request["gid"] == null) || (base.Request["gid"].ToString() == ""))
        {
            str = "";
        }
        else
        {
            str = base.Request["gid"].ToString();
        }
        string where = " Team_type='seconds'";
        if (str != "")
        {
            where = where + " and Group_id=" + str;
        }
        if ((base.Request["id"] != null) && (base.Request["id"].ToString() != ""))
        {
            where = where + " and id=" + base.Request["id"].ToString();
        }
        Team team = new Team();
        StringBuilder builder = new StringBuilder();
        DataSet set = DbHelperSQL.Page(8, this.pager.CurrentPageIndex, "Team", where, " End_time desc", "*", out num);
        if (((set != null) && (set.Tables.Count > 0)) && (set.Tables[0].Rows.Count > 0))
        {
            for (int i = 0; i < set.Tables[0].Rows.Count; i++)
            {
                DataRow row = set.Tables[0].Rows[i];
                builder.Append("<li class=\" first\">");
                builder.Append("<p class=\"time\">" + DateTime.Parse(row["Begin_time"].ToString()).ToString("yyyy-MM-dd HH:mm:ss").ToString() + "</p>");
                builder.Append("<h4><a href=\"/team.aspx?id=" + row["id"].ToString() + "\" title=\"" + row["Title"].ToString() + "\" target=\"_blank\">" + row["Title"].ToString() + "</a></h4>");
                builder.Append("<div class=\"pic\">");
                if ((Convert.ToDateTime(row["Begin_time"].ToString()) > this.beginTime) && (Convert.ToDateTime(row["End_time"].ToString()) > this.beginTime))
                {
                    builder.Append("<div class='seconds_wait'></div>");
                }
                else if ((Convert.ToDateTime(row["Begin_time"].ToString()) <= this.beginTime) && (Convert.ToDateTime(row["End_time"].ToString()) > this.beginTime))
                {
                    if ((Convert.ToInt32(row["Max_number"].ToString()) != 0) && (Convert.ToInt32(row["Now_number"].ToString()) >= Convert.ToInt32(row["Max_number"].ToString())))
                    {
                        builder.Append("<div class='isopen'></div>");
                    }
                    else
                    {
                        builder.Append("<div class='seconds_on'></div>");
                    }
                }
                else if (Convert.ToDateTime(row["End_time"].ToString()) < this.beginTime)
                {
                    builder.Append("<div class='seconds_off'></div>");
                }
                builder.Append("<a class=\"isopenlink\" href=\"/team.aspx?id=" + row["id"].ToString() + "\" title=\"" + row["Title"].ToString() + "\" target=\"_blank\"></a>");
                builder.Append("<a href=\"/team.aspx?id=" + row["id"].ToString() + "\" title=\"" + row["Title"].ToString() + "\" target=\"_blank\"><img alt=\"" + row["Title"].ToString() + "\" src=\"" + row["Image"].ToString() + "\" width=\"200\" height=\"121\"></a>");
                builder.Append("</div>");
                builder.Append("<div class=\"info\">");
                builder.Append("<p class=\"total\"><strong class=\"count\">" + row["Now_number"] + "</strong>人购买</p>");
                string discount = WebSiteHelper.GetDiscount(Helper.GetDecimal(row["Market_price"], 0M), Helper.GetDecimal(row["Team_price"], 0M));
                string[] strArray = new string[9];
                strArray[0] = "<p class=\"price\">原价：<strong class=\"old\"><span class=\"money\">\x00a5</span>";
                strArray[1] = double.Parse(row["Market_price"].ToString()).ToString("F1");
                strArray[2] = "</strong><br />折扣：<strong class=\"discount\">";
                strArray[3] = discount;
                strArray[4] = "</strong><br />现价：<strong><span class=\"money\">\x00a5</span>";
                strArray[5] = double.Parse(row["Team_price"].ToString()).ToString("F1");
                strArray[6] = "</strong><br />节省：<strong><span class=\"money\">\x00a5</span>";
                float num4 = float.Parse(row["Market_price"].ToString()) - float.Parse(row["Team_price"].ToString());
                strArray[7] = double.Parse(num4.ToString().ToString()).ToString("F1");
                strArray[8] = "</strong><br /></p>";
                builder.Append(string.Concat(strArray));
                builder.Append("</div>");
                builder.Append("</li>");
            }
        }
        this.ltTeam.Text = builder.ToString();
        this.pager.RecordCount = num;
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        base.SetTitle("秒杀抢团");
        if (!this.Page.IsPostBack)
        {
            this.initNav();
            this.initPage();
        }
    }

    protected void pager_PageChanged(object sender, EventArgs e)
    {
        this.initPage();
    }

}